package com.hutou.chuangke.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.hutou.chuangke.Bean.AlbnmlistBean;
import com.hutou.chuangke.Bean.MvlistBean;
import com.hutou.chuangke.Bean.SoundBean;
import com.hutou.chuangke.R;
import com.hutou.chuangke.adapter.IndexSoundAdapter;
import com.hutou.chuangke.uitl.CommonUtils;
import com.hutou.chuangke.widget.MyGridview;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by o on 2017/4/12.
 */
public class IndexItemActivity extends BaseActivity implements AdapterView.OnItemClickListener {
    Toolbar toolbar;
    TextView title_tv;
    Context mContext;
    MyGridview indexitemgridview;
    IndexSoundAdapter indexSoundAdapter;
    private List<AlbnmlistBean> albnmlists = new ArrayList<>();
    private List<MvlistBean> mvlists = new ArrayList<>();
    private List<SoundBean> soundlists = new ArrayList<>();
    int type = 0; //1表示专辑 2表示mv 3表示声音
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indexitem);
        mContext = IndexItemActivity.this;
        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        type = intent.getIntExtra("type",0);
        title_tv = (TextView) findViewById(R.id.title_tv);
        indexitemgridview = (MyGridview) findViewById(R.id.indexitemgridview);
        indexitemgridview.setAdapter(indexSoundAdapter);
        indexitemgridview.setOnItemClickListener(this);
        if(type==1){
            albnmlists = (List<AlbnmlistBean>) intent.getSerializableExtra("data");
            indexSoundAdapter = new IndexSoundAdapter(mContext,albnmlists,false);
            indexitemgridview.setNumColumns(3);
            title_tv.setText("推荐专辑");
        }else if(type == 2){
            mvlists = (List<MvlistBean>) intent.getSerializableExtra("data");
            indexSoundAdapter = new IndexSoundAdapter(mContext,mvlists,false);
            indexitemgridview.setNumColumns(2);
            title_tv.setText("推荐MV");
        }else if(type == 3){
            soundlists = (List<SoundBean>) intent.getSerializableExtra("data");
            indexSoundAdapter = new IndexSoundAdapter(mContext,soundlists,false);
            indexitemgridview.setNumColumns(3);
            title_tv.setText("推荐声音");
        }

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setPadding(0, CommonUtils.getStatusHeight(IndexItemActivity.this), 0, 0);
        setSupportActionBar(toolbar);
        final ActionBar ab = getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.actionbar_back);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("");
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        showQuickControl(false);


    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if(type == 1){
            Intent albnIntent = new Intent(mContext, IndexAlbumDetailActivity.class);
            albnIntent.putExtra("albnmlistBean",albnmlists.get(i));
            mContext.startActivity(albnIntent);
        }else if(type == 2){
            Intent intent = new Intent(mContext,VideoViewActivity.class);
            intent.putExtra("mv",mvlists.get(i));
            mContext.startActivity(intent);
        }else {
            Intent intent = new Intent(mContext,SingerDetailActivity.class);
            mContext.startActivity(intent);
        }
    }
}
